import 'package:flutter/material.dart';
import 'package:flutter_test_demo/static/colors/MyColors.dart';

class UserSeting extends StatefulWidget {
  UserSeting({Key key}) : super(key: key);

  @override
  _UserSetingState createState() => _UserSetingState();
}

class _UserSetingState extends State<UserSeting> {
  List jurisdictionList = [
    "开启无线网权限",
    "开启NFC",
    "开启定位",
    "开启本地权限",
    "开启蓝牙"
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("设置"),
        centerTitle: true,
        backgroundColor: MyColor.titleColor,
      ),
      body: Padding(
      padding: EdgeInsets.all(20.0),
      child: ListView(
        children:  jurisdictionList.map((item) => MySwitch(title: item)).toList(),
      ),
    ),
    );
  }
}
class MySwitch extends StatefulWidget {
  final String title;
  MySwitch({Key key, @required this.title}) : super(key: key);

  @override
  _MySwitchState createState() => _MySwitchState();
}

class _MySwitchState extends State<MySwitch> {
  bool _value = true;
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.symmetric(
        vertical: 10.0,
      ),
      child: Row(
        children: <Widget>[
          Switch(
            
            activeColor:MyColor.titleColor,
            value: _value, 
            onChanged: (val){

              setState(() {
                _value = val;
              });
            }
          ),
          Expanded(child: SizedBox()),
          Text(
            widget.title,
            style: TextStyle(
              fontSize: 18.0,
            ),
          
          )
        ]
      ),
    
    );
  }
}